package OfferCode;

/**
 * @Author Kechelle
 * @Date 2020/9/11 0:45
 * @Version 1.0
 */
public class Code58_1 {
    public static String reverseWords(String str) {
        String[] strings = str.trim().split(" ");  //去掉首尾空格
        StringBuffer sb = new StringBuffer();
        for (int i=strings.length-1;i>=0;i--){
            if (strings[i].equals("")) continue;
            sb.append(strings[i]+ " ");
        }
        return sb.toString().trim();
    }

    public static void main(String[] args) {
        String str = "  hello world!  ";
        System.out.println(Code58_1.reverseWords(str));
    }
}
